Page({
  data: {
    user: {
      first: {
        name: "",
        vip: "",
        create: "",
        image: ""
      },
      two: {
        name: "",
        vip: "",
        create: "",
        image: ""
      },
      three: {
        name: "",
        vip: "",
        create: "",
        image: ""
      }
    },
    table: [],
    select: ""
  },
  onLoad() {
    this.GetData()
  },
  GetData: function () {
    wx.request({
      url: 'https://api.xupufen.top/prod-api/system/vip/list??pageNum=1&pageSize=1000',
      method: 'GET',
      headers: {}, // 注意这里是headers，不是Headers
      data: {},
      success: (res) => {
        if (res.data.rows.length >= 3) {
          // 假设res.data.rows是一个数组，并且每个元素都有name, vip, image等属性
          const sortedRows = res.data.rows.sort((a, b) => {
            return new Date(a.cr) - new Date(b.cr);
          });

          // 分别给first, two, three赋值
          this.setData({
            'user.first': sortedRows[0],
            'user.two': sortedRows[1],
            'user.three': sortedRows[2]
          });

          // 将剩下的元素赋值给table
          this.setData({
            table: sortedRows
          }, () => {
            console.log(`数据获取成功`);
          })
        } else {
          // 如果数组长度不足3，可以根据实际情况处理
          console.log('数据长度不足');
        }
      },
      fail: (err) => {
        console.log('fail')
        console.log(err);
      },
      complete: () => {
        console.log('网络请求执行')
      }
    })
  },
  inp: function (e) {
    this.setData({
      select: e.detail.value
    })
  },
  GetSelect: function () {
    if (this.data.select != null) {
      wx.request({
        url: `https://api.xupufen.top/prod-api/system/vip/list?name=${this.data.select}`,
        method: 'GET',
        header: {}, // 注意这里是header，不是Headers
        success: (res) => {
          if(res.data.rows.length===0){
            console.log(1);
          }
          this.setData({
            table: res.data.rows.sort((a, b) => {
              return new Date(a.cr) - new Date(b.cr);
            })
          })
        },
        fail: (err) => {
          console.log(err);
        }
      })
      console.log(0);
    }
  }
})
